package com.gxa.service.impl;

import com.gxa.common.R;
import com.gxa.mapper.PurchaseRecordMapper;
import com.gxa.pojo.Receipt_Purchase;
import com.gxa.service.PurchaseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PurchaseRecordServiceImpl implements PurchaseRecordService{
    R r = new R();
    @Autowired(required = false)
    PurchaseRecordMapper purchaseRecordMapper;

    @Override
    public R reverseAuditReceiptPurchase(Map map) {

        Integer result = purchaseRecordMapper.reverseAuditReceiptPurchase(map);
        if(result !=0){
            r.setCode(200);
            r.setMsg("反审核成功");
            r.setData(null);
        }
        return r;
    }

    @Override
    public R delReceiptPurchaseRecord(Map map) {
        Integer result = purchaseRecordMapper.delReceiptPurchaseRecord(map);
        if(result !=0){
            r.setCode(200);
            r.setMsg("删除成功");
            r.setData(null);
        }else{
            r.setCode(201);
            r.setMsg("删除失败");
            r.setData(null);
        }
        return r;
    }

    @Override
    public R queryAllRecode(int receipt_purchase_business_type) {

        List<Receipt_Purchase> list = purchaseRecordMapper.queryAllRecode(receipt_purchase_business_type);
        if(list != null){
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(list);
        }
        return r;
    }

    @Override
    public R queryOneRecord(String receipt_purchase_id) {
        Receipt_Purchase  receipt_purchase = purchaseRecordMapper.queryOneRecode(receipt_purchase_id);
        if(receipt_purchase != null){
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(receipt_purchase);
        }
        return r;
    }

    @Override
    public R queryRecord(int receipt_purchase_business_type,String condition, String startDate, String endDate) {
        List<Receipt_Purchase> receipt_purchases = purchaseRecordMapper.queryRecode(receipt_purchase_business_type,condition,startDate,endDate);
        if(receipt_purchases != null){
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(receipt_purchases);
        }
        return r;
    }
}
